//
//  LXStatusToolbar.swift
//  weibo
//
//  Created by 罗心 on 16/6/29.
//  Copyright © 2016年 罗心. All rights reserved.
//

import UIKit

class LXStatusToolbar: UIView {
    var retweetButton: UIButton?
    var commentButton: UIButton?
    var likeButton: UIButton?
    
    var status:LXStatus?{
        didSet{
            retweetButton?.setTitle(status?.repostsStr, forState: UIControlState.Normal)
            commentButton?.setTitle(status?.commentsStr, forState: UIControlState.Normal)
            likeButton?.setTitle(status?.attitudesStr, forState: UIControlState.Normal)
        }
    }
    
    override init(frame: CGRect) {
        super.init(frame: frame)
        setupUI()
    }
    
    required init?(coder aDecoder: NSCoder) {
        fatalError("init(coder:) has not been implemented")
    }
    
    private func setupUI(){
        
        retweetButton = addChildButtons("timeline_icon_retweet", title: "转发")
        commentButton = addChildButtons("timeline_icon_comment", title: "评论")
        likeButton = addChildButtons("timeline_icon_unlike", title: "赞")
        
        retweetButton?.snp_makeConstraints(closure: { (make) in
            make.top.leading.bottom.equalTo(self)
            make.width.equalTo(commentButton!)
        })
        commentButton?.snp_makeConstraints(closure: { (make) in
            make.top.bottom.equalTo(self)
            make.leading.equalTo((retweetButton?.snp_trailing)!)
            make.width.equalTo(likeButton!)
        })
        likeButton?.snp_makeConstraints(closure: { (make) in
            make.top.bottom.trailing.equalTo(self)
            make.leading.equalTo((commentButton?.snp_trailing)!)
        })
        
    }
    
    //创建button
    private func addChildButtons(imageName: String, title: String) -> UIButton{
        let button = UIButton()
        button.setImage(UIImage(named:imageName), forState: UIControlState.Normal)
        button.setTitle(title, forState: UIControlState.Normal)
        button.setTitleColor(UIColor.darkGrayColor(), forState: UIControlState.Normal)
        button.titleLabel?.font = UIFont.systemFontOfSize(14)
        button.setBackgroundImage(UIImage(named: "timeline_card_bottom_background_highlighted"), forState: UIControlState.Highlighted)
        button.setBackgroundImage(UIImage(named: "timeline_card_bottom_background"), forState: UIControlState.Normal)
        addSubview(button)
        return button
    }

}
